home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / diskmags / 3565-4.665 / dmg-4385 / issue_10 / 24.pne < prev    next >
Text File  |  1987-04-21  |  14KB  |  495 lines

  1.  
  2.  
  3.  
  4.  You should have allready read basic tut 10/1 before attemting 
  5. this article 
  6.  
  7. This is a more or less up and running version.  But I have not 
  8. included any tests to see if the jigsaw is completed or not.
  9.  
  10.  
  11. Lesson 5
  12.  
  13.  
  14. 10 rem **************************
  15. 20 rem ***                    ***
  16. 30 rem ***     JIGSAW   3     ***
  17. 40 rem ***                    ***
  18. 50 rem **************************
  19. 60 if mode<>0 then mode 0
  20. 70 cls : key off : curs off : hide on
  21. 80 on error goto 2140
  22. 90 if drvmap=1 then drive$="A" : goto 170
  23. 100 if drvmap>1 then print "Select drive, or wait, 20 seconds!"
  24. 110 D$=""
  25. 120 repeat
  26. 130 D$=inkey$
  27. 140 inc TRP
  28. 150 until D$<>"" or TRP=25000
  29. 160 if D$="" then D$="A"
  30. 170 DRV=drive : drive$=D$ : dir$=D$+":\"
  31. 180 X1=63 : X2=319 : Y1=0 : Y2=199
  32. 190 X3=0 : X4=X1 : Y3=120 : Y4=Y2
  33. 200 JIGHRZ=5 : JIGVER=5 : JBUTS=9
  34. 210 JIG=25 : JSPRHT=39 : JSPRWD=48
  35. 220 JIGFST=4 : JIGLST=JIG+3 : MSPR=2 : JDSPR=4
  36. 230 JIGX1=X1+1 : JIGX2=JIGX1+JIGHRZ*JSPRWD
  37. 240 JIGY1=Y1+2 : JIGY2=JIGY1+JIGVER*JSPRHT
  38. 250 JIGX3=X3 : JIGX4=X4
  39. 260 JIGY3=Y3 : JIGY4=Y4
  40. 270 dim JX(JIG) dim JY(JIG)
  41. 280 dim SWP(JIG),SPR(JIG+1)
  42. 290 rem
  43. 300 rem ------ grab sprites & make jigsaw
  44. 310 rem
  45. 320 if length(1)<>0 then goto 410
  46. 330 erase 1
  47. 340 cls : locate 10,0 : print "LOAD A SPRITE BANK"
  48. 350 show on : SPR$=file select$("*.MBK")
  49. 360 F$=SPR$ : BNK=1 : gosub 700
  50. 370 rem
  51. 380 rem
  52. 390 rem ---- Load a picture
  53. 400 rem
  54. 410 if length(6)<>0 then goto 490
  55. 420 if length(6)=0 then reserve as screen 6
  56. 430 cls : locate 10,0 : print "LOAD PICTURE"
  57. 440 show on : SCR$=file select$("*.*")
  58. 450 F$=SCR$ : BNK=6 : gosub 700
  59. 460 rem
  60. 470 rem ---- Load a packed screen
  61. 480 rem
  62. 490 if length(7)<>0 then goto 560
  63. 500 if length(7)=0 then reserve as screen 7
  64. 510 cls : locate 10,0 : print "LOAD PACed FILE"
  65. 520 show on : PSCR$=file select$("*.pac")
  66. 530 F$=PSCR$ : BNK=8 : gosub 790
  67. 540 rem
  68. 550 rem
  69. 560 get palette (6)
  70. 570 screen copy 6 to back : screen copy 6 to physic
  71. 580 reduce 6 to 7,JIGX1,JIGY1,JIGX2,JIGY2
  72. 590 reduce 6 to 7,JIGX3,JIGY3,JIGX4,JIGY4
  73. 600 fade 5
  74. 610 fade 5,6
  75. 620 get palette (6)
  76. 630 screen copy 7 to back : screen copy 7 to physic
  77. 640 rem
  78. 650 wait 20 : gosub 1340 : goto 1490
  79. 660 rem
  80. 670 rem
  81. 680 rem ------ FILE LOADER
  82. 690 rem
  83. 700 hide on : cls : load F$,BNK
  84. 710 locate 10,10
  85. 720 print F$;" IS LOADED" : wait 50
  86. 730 cls : return 740 rem
  87. 750 rem ----- PACed FILE LOADER
  88. 760 rem
  89. 770 rem  get size of file to unsquash
  90. 780 rem
  91. 790 hide on : cls
  92. 800 open in #1,F$ : LF=lof(#1) : close #1
  93. 810 erase BNK : reserve as work BNK,LF
  94. 820 bload F$,BNK
  95. 830 rem
  96. 840 rem  unsquashing file in a screen bank
  97. 850 rem
  98. 860 copy start(8),start(8)+LF to start(7)
  99. 870 unsquash 7,LF
  100. 880 locate 10,10
  101. 890 print F$;" IS LOADED" : wait 50
  102. 900 cls : return 910 rem
  103. 920 rem --- Setting the Zones ---
  104. 930 rem
  105. 940 rem
  106. 950 reset zone : restore 2210
  107. 960 for F=1 to JBUTS
  108. 970 read A,B,C,D
  109. 980 set zone F,A,B to C,D
  110. 990 box A,B to C,D
  111. 1000 next F
  112. 1010 gosub 1340
  113. 1020 rem
  114. 1030 x mouse=11 : y mouse=11
  115. 1040 mouseon : show on
  116. 1050 MK=0
  117. 1060 repeat
  118. 1070 rem
  119. 1080 if x mouse<JIGX1 or x mouse>JIGX2-JSPRWD+2 or y mouse<JIGY1 or 
  120. y mouse>JIGY2-JSPRHT+2 then change mouse MSPR else change mouse JDSPR
  121. 1090 MK=mouse key
  122. 1100 until MK<>0
  123. 1110 ZN=zone(0)
  124. 1120 rem
  125. 1130 shoot : hide on : wait 10 : mouseoff
  126. 1140 rem
  127. 1150 rem  --- Find Which Zone ---
  128. 1160 rem
  129. 1170 if ZN=0 then goto 1040
  130. 1180 if ZN>0 and ZN<=9 then goto 1190 else goto 1280
  131. 1190 if ZN=1 then JDSPR=JIGFST
  132. 1200 if ZN=2 then JDSPR=JIGLST
  133. 1210 if ZN=3 then inc JDSPR : gosub 2070
  134. 1220 if ZN=4 then dec JDSPR : gosub 2090
  135. 1230 if ZN=5 then goto 1040
  136. 1240 if ZN=6 then goto 1040
  137. 1250 if ZN=7 then goto 1040
  138. 1260 if ZN=8 then goto 1040
  139. 1270 if ZN=9 then default : mouseon : end
  140. 1280 if x mouse>JIGX1 and x mouse<JIGX2 and y mouse>JIGY1 and y 
  141. mouse<JIGY2 then goto 1990
  142. 1290 goto 1040
  143. 1300 rem
  144. 1310 rem
  145. 1320 rem ***  draw jigsaw grid zones ***
  146. 1330 rem
  147. 1340 GX1=JIGX1 : GX2=JIGX2 : GY1=JIGY1 : GY2=JIGY2
  148. 1350 GX3=GX1+JSPRWD : GY3=GY1+JSPRHT
  149. 1360 for F=1 to JIG
  150. 1370 JX(F)=GX1 : JY(F)=GY1
  151. 1380 GX1=GX1+JSPRWD
  152. 1390 if GX1>=JSPRWD*JIGHRZ+JIGX1 then GX1=JIGX1 : GY1=GY1+JSPRHT
  153. 1400 next F
  154. 1410 for F=1 to JIG
  155. 1420 set zone F+JBUTS,JX(F),JY(F) to JX(F)+JSPRWD,JY(F)+JSPRHT
  156. 1430 box JX(F),JY(F) to JX(F)+JSPRWD,JY(F)+JSPRHT
  157. 1440 next F
  158. 1450 return 1460 rem
  159. 1470 rem --- Convert picture into sprites
  160. 1480 rem
  161. 1490 JX=JIGX1 : JY=JIGY1
  162. 1500 for F=1 to JIG
  163. 1510 get sprite JX,JY,F
  164. 1520 JX=JX+JSPRWD
  165. 1530 if JX>=JIGX2 then JX=X1+1 : JY=JY+JSPRHT
  166. 1540 next F
  167. 1550 rem
  168. 1560 rem  ---- Mixing Sprites up ----
  169. 1570 rem
  170. 1580 for F=0 to JIG
  171. 1590 SPR(F)=F
  172. 1600 next F
  173. 1610 rem
  174. 1620 repeat 1630 NUM=rnd(JIG)+1
  175. 1640 if SWP(NU)=0 and SPR(NUM)<>0 then SWP(NU)=SPR(NUM) else goto 
  176. 1630
  177. 1650 inc NU : SPR(NUM)=0
  178. 1660 until NU=JIG
  179. 1670 rem
  180. 1680 rem ---- display to screen  ----
  181. 1690 rem
  182. 1700 DX=JIGX1 : DY=JIGY1
  183. 1710 cls physic,0,JIGX1,JIGY1+1 to JIGX2,JIGY2
  184. 1720 cls back,0,JIGX1,JIGY1+1 to JIGX2,JIGY2
  185. 1730 for F=1 to JIG
  186. 1740 sprite 1,DX,DY,SWP(F-1)
  187. 1750 wait vbl : put sprite 1
  188. 1760 DX=DX+JSPRWD
  189. 1770 if DX>=JIGX2 then DX=JIGX1 : DY=DY+JSPRHT
  190. 1780 rem
  191. 1790 next F
  192. 1800 rem
  193. 1810 rem --- Re-Convert picture into sprites ---
  194. 1820 rem
  195. 1830 JX=JIGX1 : JY=JIGY1
  196. 1840 for F=1 to JIG
  197. 1850 get sprite JX,JY,F
  198. 1860 JX=JX+JSPRWD
  199. 1870 if JX>=JIGX2 then JX=X1+1 : JY=JY+JSPRHT
  200. 1880 next F
  201. 1890 wait 75
  202. 1900 rem
  203. 1910 cls physic,0,JIGX1,JIGY1+1 to JIGX2,JIGY2
  204. 1920 cls back,0,JIGX1,JIGY1+1 to JIGX2,JIGY2
  205. 1930 sprite off
  206. 1940 goto 940
  207. 1950 rem
  208. 1960 rem
  209. 1970 rem +++ placing pieces in jigsaw +++
  210. 1980 rem
  211. 1990 DJP=ZN-9
  212. 2000 rem
  213. 2010 hide on : change mouse 2
  214. 2020 sprite 1,JX(DJP),JY(DJP),JDSPR-3
  215. 2030 wait vbl : put sprite 1
  216. 2040 x mouse=30 : y mouse=18
  217. 2050 goto 1040
  218. 2060 rem
  219. 2070 if JDSPR=1 then JDSPR=JIGFST+1
  220. 2080 if JDSPR>JIGLST then JDSPR=JIGFST
  221. 2090 if JDSPR=0 then JDSPR=JIGLST
  222. 2100 if JDSPR<JIGFST then JDSPR=JIGLST
  223. 2110 return 2120 rem ------ ERROR TRAPPING
  224. 2130 rem
  225. 2140 if errn=83 then D$="A" : goto 170
  226. 2150 default : mouseon 2160 if errn<>83 then cls : print "ERROR AT 
  227. LINE";errl : print "ERROR IS";errn
  228. 2170 print "Enter Command  ERROR ERRN to get help"
  229. 2180 rem
  230. 2190 rem data for ZONES and JIGSAW
  231. 2200 rem
  232. 2210 data 0,0,32,18,32,0,63,18
  233. 2220 data 0,19,32,37,32,19,63,37
  234. 2230 data 0,38,32,66,32,38,63,66
  235. 2240 data 0,67,32,95,32,67,63,95
  236. 2250 data 0,96,63,119
  237. 2260 data 0,67,32,95,32,67,63,95 
  238.  
  239.  
  240. Gosh, I bet that you thought that it would go on for ever.  Well 
  241. at least a third of it is rem statements.  And most of the rest 
  242. has already been covered, so it is not  so bad really - otherr 
  243. than the space that it is takeing up.
  244.  
  245. Lines:
  246. 10 rem **************************
  247. 20 rem ***                    ***
  248. 30 rem ***     JIGSAW   3     ***
  249. 40 rem ***                    ***
  250. 50 rem **************************
  251. 60 if mode<>0 then mode 0
  252. 70 cls : key off : curs off : hide on
  253.  
  254. Should be clear enough to you.
  255.  
  256. Line:
  257. 80 on error goto 2140
  258.  
  259. Tests for errors.  IT is not intended to work all that well at the 
  260. moment.  After all I am only testing a partial programme at the 
  261. moment, so it does not need to be that good.
  262.  
  263. Lines:
  264. 90 if drvmap=1 then drive$="A" : goto 170
  265. 100 if drvmap>1 then print "Select drive, or wait, 20 seconds!"
  266. 110 D$=""
  267. 120 repeat 130 D$=inkey$
  268. 140 inc TRP
  269. 150 until D$<>"" or TRP=25000
  270. 160 if D$="" then D$="A"
  271. 170 DRV=drive : drive$=D$ : dir$=D$+":\"
  272.  
  273. Are the new default drive bit.  It does not work as I would like, 
  274. but it does what is intended.  It alows you to press the key of 
  275. the drive to default to, or after 20 seconds it defaults to drive 
  276. A: on its own.
  277.  
  278. Lines:
  279. 180 X1=63 : X2=319 : Y1=0 : Y2=199
  280. 190 X3=0 : X4=X1 : Y3=120 : Y4=Y2
  281. 200 JIGHRZ=5 : JIGVER=5 : JBUTS=9
  282. 210 JIG=25 : JSPRHT=39 : JSPRWD=48
  283. 220 JIGFST=4 : JIGLST=JIG+3 : MSPR=2 : JDSPR=4
  284. 230 JIGX1=X1+1 : JIGX2=JIGX1+JIGHRZ*JSPRWD
  285. 240 JIGY1=Y1+2 : JIGY2=JIGY1+JIGVER*JSPRHT
  286. 250 JIGX3=X3 : JIGX4=X4
  287. 260 JIGY3=Y3 : JIGY4=Y4
  288. 270 dim JX(JIG) dim JY(JIG)
  289. 280 dim SWP(JIG),SPR(JIG+1)
  290.  
  291. Are variables used in the programme.
  292.  
  293. And that is As far as I can go in this tutorial, due to the above 
  294. mentioned problems. 
  295.  
  296. 290 rem
  297. 300 rem ------ grab sprites & make jigsaw
  298. 310 rem
  299. 320 if length(1)<>0 then goto 410
  300. 330 erase 1
  301. 340 cls : locate 10,0 : print "LOAD A SPRITE BANK"
  302. 350 show on : SPR$=file select$("*.MBK")
  303. 360 F$=SPR$ : BNK=1 : gosub 700
  304. 370 rem
  305. 380 rem
  306. 390 rem ---- Load a picture
  307. 400 rem
  308. 410 if length(6)<>0 then goto 490
  309. 420 if length(6)=0 then reserve as screen 6
  310. 430 cls : locate 10,0 : print "LOAD PICTURE"
  311. 440 show on : SCR$=file select$("*.*")
  312. 450 F$=SCR$ : BNK=6 : gosub 700
  313. 460 rem
  314. 470 rem ---- Load a packed screen
  315. 480 rem
  316. 490 if length(7)<>0 then goto 560
  317. 500 if length(7)=0 then reserve as screen 7
  318. 510 cls : locate 10,0 : print "LOAD PACed FILE"
  319. 520 show on : PSCR$=file select$("*.pac")
  320. 530 F$=PSCR$ : BNK=8 : gosub 790
  321. 540 rem
  322. 550 rem
  323. 560 get palette (6)
  324. 570 screen copy 6 to back : screen copy 6 to physic
  325. 580 reduce 6 to 7,JIGX1,JIGY1,JIGX2,JIGY2
  326. 590 reduce 6 to 7,JIGX3,JIGY3,JIGX4,JIGY4
  327. 600 fade 5
  328. 610 fade 5,6
  329. 620 get palette (6)
  330. 630 screen copy 7 to back : screen copy 7 to physic
  331. 640 rem
  332. 650 wait 20 : gosub 1340 : goto 1490
  333. 660 rem
  334. 670 rem
  335. 680 rem ------ FILE LOADER
  336. 690 rem
  337. 700 hide on : cls : load F$,BNK
  338. 710 locate 10,10
  339. 720 print F$;" IS LOADED" : wait 50
  340. 730 cls : return
  341. 740 rem
  342. 750 rem ----- PACed FILE LOADER
  343. 760 rem
  344. 770 rem  get size of file to unsquash
  345. 780 rem
  346. 790 hide on : cls
  347. 800 open in #1,F$ : LF=lof(#1) : close #1
  348. 810 erase BNK : reserve as work BNK,LF
  349. 820 bload F$,BNK
  350. 830 rem
  351. 840 rem  unsquashing file in a screen bank
  352. 850 rem
  353. 860 copy start(8),start(8)+LF to start(7)
  354. 870 unsquash 7,LF
  355. 880 locate 10,10
  356. 890 print F$;" IS LOADED" : wait 50
  357. 900 cls : return 910 rem
  358. 920 rem --- Setting the Zones ---
  359. 930 rem
  360. 940 rem
  361. 950 reset zone : restore 2210
  362. 960 for F=1 to JBUTS
  363. 970 read A,B,C,D
  364. 980 set zone F,A,B to C,D
  365. 990 box A,B to C,D
  366. 1000 next F
  367. 1010 gosub 1340
  368. 1020 rem
  369. 1030 x mouse=11 : y mouse=11
  370. 1040 mouseon : show on 1050 MK=0
  371. 1060 repeat
  372. 1070 rem
  373. 1080 if x mouse<JIGX1 or x mouse>JIGX2-JSPRWD+2 or y mouse<JIGY1 or 
  374. y mouse>JIGY2-JSPRHT+2 then change mouse MSPR else change mouse JDSPR
  375. 1090 MK=mouse key
  376. 1100 until MK<>0
  377. 1110 ZN=zone(0)
  378. 1120 rem
  379. 1130 shoot : hide on : wait 10 : mouseoff
  380. 1140 rem
  381. 1150 rem  --- Find Which Zone ---
  382. 1160 rem
  383. 1170 if ZN=0 then goto 1040
  384. 1180 if ZN>0 and ZN<=9 then goto 1190 else goto 1280
  385. 1190 if ZN=1 then JDSPR=JIGFST
  386. 1200 if ZN=2 then JDSPR=JIGLST
  387. 1210 if ZN=3 then inc JDSPR : gosub 2070
  388. 1220 if ZN=4 then dec JDSPR : gosub 2090
  389. 1230 if ZN=5 then goto 1040
  390. 1240 if ZN=6 then goto 1040
  391. 1250 if ZN=7 then goto 1040
  392. 1260 if ZN=8 then goto 1040
  393. 1270 if ZN=9 then default : mouseon : end
  394. 1280 if x mouse>JIGX1 and x mouse<JIGX2 and y mouse>JIGY1 and y 
  395. mouse<JIGY2 then goto 1990
  396. 1290 goto 1040
  397. 1300 rem
  398. 1310 rem
  399. 1320 rem ***  draw jigsaw grid zones ***
  400. 1330 rem
  401. 1340 GX1=JIGX1 : GX2=JIGX2 : GY1=JIGY1 : GY2=JIGY2
  402. 1350 GX3=GX1+JSPRWD : GY3=GY1+JSPRHT
  403. 1360 for F=1 to JIG
  404. 1370 JX(F)=GX1 : JY(F)=GY1
  405. 1380 GX1=GX1+JSPRWD
  406. 1390 if GX1>=JSPRWD*JIGHRZ+JIGX1 then GX1=JIGX1 : GY1=GY1+JSPRHT
  407. 1400 next F
  408. 1410 for F=1 to JIG
  409. 1420 set zone F+JBUTS,JX(F),JY(F) to JX(F)+JSPRWD,JY(F)+JSPRHT
  410. 1430 box JX(F),JY(F) to JX(F)+JSPRWD,JY(F)+JSPRHT
  411. 1440 next F
  412. 1450 return 1460 rem
  413. 1470 rem --- Convert picture into sprites
  414. 1480 rem
  415. 1490 JX=JIGX1 : JY=JIGY1
  416. 1500 for F=1 to JIG
  417. 1510 get sprite JX,JY,F
  418. 1520 JX=JX+JSPRWD
  419. 1530 if JX>=JIGX2 then JX=X1+1 : JY=JY+JSPRHT
  420. 1540 next F
  421. 1550 rem
  422. 1560 rem  ---- Mixing Sprites up ----
  423. 1570 rem
  424. 1580 for F=0 to JIG
  425. 1590 SPR(F)=F
  426. 1600 next F
  427. 1610 rem
  428. 1620 repeat 1630 NUM=rnd(JIG)+1
  429. 1640 if SWP(NU)=0 and SPR(NUM)<>0 then SWP(NU)=SPR(NUM) else goto 
  430. 1630
  431. 1650 inc NU : SPR(NUM)=0
  432. 1660 until NU=JIG
  433. 1670 rem
  434. 1680 rem ---- display to screen  ----
  435. 1690 rem
  436. 1700 DX=JIGX1 : DY=JIGY1
  437. 1710 cls physic,0,JIGX1,JIGY1+1 to JIGX2,JIGY2
  438. 1720 cls back,0,JIGX1,JIGY1+1 to JIGX2,JIGY2
  439. 1730 for F=1 to JIG
  440. 1740 sprite 1,DX,DY,SWP(F-1)
  441. 1750 wait vbl : put sprite 1
  442. 1760 DX=DX+JSPRWD
  443. 1770 if DX>=JIGX2 then DX=JIGX1 : DY=DY+JSPRHT
  444. 1780 rem
  445. 1790 next F
  446. 1800 rem
  447. 1810 rem --- Re-Convert picture into sprites ---
  448. 1820 rem
  449. 1830 JX=JIGX1 : JY=JIGY1
  450. 1840 for F=1 to JIG
  451. 1850 get sprite JX,JY,F
  452. 1860 JX=JX+JSPRWD
  453. 1870 if JX>=JIGX2 then JX=X1+1 : JY=JY+JSPRHT
  454. 1880 next F
  455. 1890 wait 75
  456. 1900 rem
  457. 1910 cls physic,0,JIGX1,JIGY1+1 to JIGX2,JIGY2
  458. 1920 cls back,0,JIGX1,JIGY1+1 to JIGX2,JIGY2
  459. 1930 sprite off 1940 goto 940
  460. 1950 rem
  461. 1960 rem
  462. 1970 rem +++ placing pieces in jigsaw +++
  463. 1980 rem
  464. 1990 DJP=ZN-9
  465. 2000 rem
  466. 2010 hide on : change mouse 2
  467. 2020 sprite 1,JX(DJP),JY(DJP),JDSPR-3
  468. 2030 wait vbl : put sprite 1
  469. 2040 x mouse=30 : y mouse=18
  470. 2050 goto 1040
  471. 2060 rem
  472. 2070 if JDSPR=1 then JDSPR=JIGFST+1
  473. 2080 if JDSPR>JIGLST then JDSPR=JIGFST
  474. 2090 if JDSPR=0 then JDSPR=JIGLST
  475. 2100 if JDSPR<JIGFST then JDSPR=JIGLST
  476. 2110 return 2120 rem ------ ERROR TRAPPING
  477. 2130 rem
  478. 2140 if errn=83 then D$="A" : goto 170
  479. 2150 default : mouseon
  480. 2160 if errn<>83 then cls : print "ERROR AT LINE";errl : print 
  481. "ERROR IS";errn
  482. 2170 print "Enter Command  ERROR ERRN to get help"
  483. 2180 rem
  484. 2190 rem data for ZONES and JIGSAW
  485. 2200 rem
  486. 2210 data 0,0,32,18,32,0,63,18
  487. 2220 data 0,19,32,37,32,19,63,37
  488. 2230 data 0,38,32,66,32,38,63,66
  489. 2240 data 0,67,32,95,32,67,63,95
  490. 2250 data 0,96,63,119
  491. 2260 data 0,67,32,95,32,67,63,95 
  492.  
  493.  
  494.  
  495.